package com.saint.swipemenulistview.activity;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.view.View;

import com.saint.swipemenulistview.R;

/**
 * Created by Administrator on 2017/11/7.
 */

public class NotificationTestActivity extends BaseActivity {
    @Override
    protected int setContent() {
        return R.layout.act_notification;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initDate() {

    }

    @Override
    protected void startAct(Activity startAct) {
        intent = new Intent(startAct, NotificationTestActivity.class);
        startAct.startActivity(intent);
    }

    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.notification_btn:

                Intent intent1 = new Intent(this, MainActivity.class);

                PendingIntent intent = PendingIntent.getActivity(this, 0, intent1, 0);

                sendNotification(this, intent);


                break;
            case R.id.notification_btn2:

                Intent intent2 = new Intent();

                PendingIntent intent3 = PendingIntent.getActivity(this, 0, intent2, 0);

                sendNotification(this, intent3);


                break;
            default:
                break;
        }
    }

    public static void sendNotification(Context context, PendingIntent pendingIntent) {
        Notification notification = null;
//        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) {
//            notification = new Notification.Builder(context)
//                    .setSmallIcon(R.mipmap.ic_launcher_round)
////                    .setContentTitle(context.getResources().getString(R.string.app_name))
//                    .setContentText("内容")
//                    .setAutoCancel(true)
//                    .setContentIntent(pendingIntent)
//                    .build();
//        } else {
            notification = new Notification(R.mipmap.ic_launcher, context.getResources().getString(R.string.app_name), System.currentTimeMillis());
            notification.contentIntent = pendingIntent;
//        }
        NotificationManager manager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
        manager.notify(0, notification);
    }

}
